﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Hostal.Bussines.Entities;
using Hostal.Bussines.Logic;
using Hostal.Bussines.Logic.Service;
using Microsoft.Practices.Unity;

namespace Hostal.MVC.Controllers
{
    public class ProveedorController : Controller
    {
        [Dependency]
        public IProveedorService  proveedorServicce { get; set; }

        //
        // GET: /Proveedor/

        public ActionResult Index()
        {
            var lista = proveedorServicce.GetAllFromProveedor();
            return View(lista);
        }

        [HttpPost]
        public ActionResult Index(string razon)
        {
            var lista = proveedorServicce.GetAllFromProveedorbyRazonSocial(razon);
            return View(lista);
        }

        public ActionResult Create()
        {
            var proveedor = new Proveedore();
            return View(proveedor);
        }

        [HttpPost]
        public ActionResult Create(Proveedore proveedor)
        {
            proveedorServicce.AddProveedor(proveedor);
            return RedirectToAction("Index");
        }

        public ActionResult Edit(Int32 id)
        {
            var proveedor = proveedorServicce.GetFromProveedorById(id);
            return View(proveedor);
        }

        [HttpPost]
        public ActionResult Edit(Proveedore proveedor)
        {
            proveedorServicce.AddProveedor(proveedor);
            return RedirectToAction("Index");
        }

        public ActionResult Delete(Int32 id)
        {
            proveedorServicce.RemoveProveedor(id);
            return RedirectToAction("Index");
        }

    }
}
